package com.denlaku.longan.service.impl;

import com.denlaku.longan.anno.RequiredTx;
import com.denlaku.longan.repository.GoingInRepository;
import com.denlaku.longan.service.GoingInService;
import com.denlaku.longan.util.SnowflakeUtils;
import com.denlaku.longan.vo.GoingIn;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author tianx
 */
@Service
public class GoingInServiceImpl implements GoingInService {
    @Autowired
    private GoingInRepository goingInRepository;

    @Override
    @RequiredTx
    public void batchAdd(List<GoingIn> goingInList) {
        if (CollectionUtils.isNotEmpty(goingInList)) {
            goingInList.forEach(goingIn -> goingIn.setId(SnowflakeUtils.nextId()));
            goingInRepository.batchAdd(goingInList);
        }
    }

    @Override
    @RequiredTx
    public void delete(Long tenantId, List<Long> componentIds) {
        goingInRepository.delete(tenantId, componentIds);
    }

    @Override
    public List<GoingIn> list(Long tenantId, List<Long> componentIds) {
        return goingInRepository.list(tenantId, componentIds);
    }

}
